package org.example.steamshop.repository;


import java.util.List;

import org.example.steamshop.model.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface OrderRepository extends JpaRepository<Order, Long> {
    List<Order> findByUserId(Long userId);

    @Modifying
    @Query("DELETE FROM Order o WHERE o.id = :orderId AND o.user.id = :userId")
    int deleteByOrderIdAndUserId(@Param("orderId") Long orderId,
                                 @Param("userId") Long userId);

    // 添加检查订单是否属于用户的方法
    boolean existsByIdAndUserId(Long orderId, Long userId);

}